package uk.co.hs.web.util;

import java.io.Serializable;

import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import uk.co.hs.constants.HsConstants;

/**
 * JodaDateAndTimeDTO.
 */
public class JodaDateAndTimeDTO implements Serializable
{
  private static final long serialVersionUID = -6005627851688830672L;
  private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormat.forPattern(HsConstants.SCREEN_DATE_FORMAT);
  private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormat.forPattern(HsConstants.SCREEN_TIME_FORMAT);
  private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern(HsConstants.SCREEN_DATE_TIME_FORMAT);

  private String mDate, mTime;

  public void setDateTime(DateTime aDateTime)
  {
    if (aDateTime == null)
    {
      mDate = null;
      mTime = null;
    }
    else
    {
      mDate = DATE_FORMATTER.print(aDateTime);
      mTime = TIME_FORMATTER.print(aDateTime);
    }
  }

  public static DateTime getDateTimeAsString(String aDateTime)
  {
    return DATE_TIME_FORMATTER.parseDateTime(aDateTime);
  }

  public DateTime getDateTime()
  {
    if (mDate == null || mDate.equals("") || mTime == null || mTime.equals(""))
    {
      return null;
    }
    return DATE_TIME_FORMATTER.parseDateTime(mDate + " " + mTime);
  }

  /**
   * @return the date
   */
  public String getDate()
  {
    return mDate;
  }

  /**
   * @param aDate the date to set
   */
  public void setDate(String aDate)
  {
    mDate = aDate;
  }

  /**
   * @return the time
   */
  public String getTime()
  {
    return mTime;
  }

  /**
   * @param aTime the time to set
   */
  public void setTime(String aTime)
  {
    mTime = aTime;
  }
}
